package com.ruoyi.project.bajiaostar.cooperationDataManagement.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.bajiaostar.cooperationDataManagement.domain.CooperationDataManagement;
import com.ruoyi.project.bajiaostar.cooperationDataManagement.domain.FindDataManagementReq;
import com.ruoyi.project.bajiaostar.cooperationDataManagement.domain.FindDataResp;
import com.ruoyi.project.bajiaostar.cooperationDataManagement.service.ICooperationDataManagementService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 渠道分析管理Controller
 * 
 * @author 谢少辉
 * @date 2025-08-20
 */
@Controller
@RequestMapping("/bajiaostar/cooperationDataManagement")
public class CooperationDataManagementController extends BaseController
{
    private String prefix = "bajiaostar/cooperationDataManagement";

    @Autowired
    private ICooperationDataManagementService cooperationDataManagementService;

    @RequiresPermissions("bajiaostar:cooperationDataManagement:view")
    @GetMapping()
    public String cooperationDataManagement()
    {
        return prefix + "/cooperationDataManagement";
    }

    /**
     * 查询渠道分析管理列表
     */
    @RequiresPermissions("bajiaostar:cooperationDataManagement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CooperationDataManagement cooperationDataManagement)
    {
        startPage();
        List<CooperationDataManagement> list = cooperationDataManagementService.selectCooperationDataManagementList(cooperationDataManagement);
        return getDataTable(list);
    }

    /**
     * 导出渠道分析管理列表
     */
    @RequiresPermissions("bajiaostar:cooperationDataManagement:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CooperationDataManagement cooperationDataManagement)
    {
        List<CooperationDataManagement> list = cooperationDataManagementService.selectCooperationDataManagementList(cooperationDataManagement);
        ExcelUtil<CooperationDataManagement> util = new ExcelUtil<CooperationDataManagement>(CooperationDataManagement.class);
        return util.exportExcel(list, "cooperationDataManagement");
    }

    /**
     * 新增渠道分析管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存渠道分析管理
     */
    @RequiresPermissions("bajiaostar:cooperationDataManagement:add")
    @Log(title = "渠道分析管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CooperationDataManagement cooperationDataManagement)
    {
        return toAjax(cooperationDataManagementService.insertCooperationDataManagement(cooperationDataManagement));
    }

    /**
     * 修改渠道分析管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CooperationDataManagement cooperationDataManagement = cooperationDataManagementService.selectCooperationDataManagementById(id);
        mmap.put("cooperationDataManagement", cooperationDataManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存渠道分析管理
     */
    @RequiresPermissions("bajiaostar:cooperationDataManagement:edit")
    @Log(title = "渠道分析管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CooperationDataManagement cooperationDataManagement)
    {
        return toAjax(cooperationDataManagementService.updateCooperationDataManagement(cooperationDataManagement));
    }

    /**
     * 删除渠道分析管理
     */
    @RequiresPermissions("bajiaostar:cooperationDataManagement:remove")
    @Log(title = "渠道分析管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cooperationDataManagementService.deleteCooperationDataManagementByIds(ids));
    }


    /**
     * 查询所有渠道
     */
    @Log(title = "渠道分析管理-查询所有渠道", businessType = BusinessType.OTHER)
    @PostMapping( "/findAddPowderPlan")
    @ResponseBody
    public AjaxResult findAddPowderPlan(String ids)
    {
        List<String> plan = cooperationDataManagementService.findAddPowderPlan();
        return AjaxResult.success(plan);
    }


    @Log(title = "渠道分析管理-统计管理", businessType = BusinessType.OTHER)
    @PostMapping( "/findDataManagement")
    @ResponseBody
    public AjaxResult findDataManagement(FindDataManagementReq req)
    {
        FindDataResp dataManagement = cooperationDataManagementService.findDataManagement(req);
        return AjaxResult.success(dataManagement);
    }
}
